package mya.mes.mdc.logic.dispatch.core;

import mya.mes.mdc.model.system.RegularReminders;
import mya.mes.mdc.constant.Sysconstant;

import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class SysManager {

    private static SysManager _instance = new SysManager();
    private ScheduledExecutorService executorService = null;

    private SysManager() {

    }

    public static SysManager getInstance() {
        return _instance;
    }


    public synchronized void start(List<RegularReminders> regularReminderses) throws Exception {
        if (regularReminderses != null && regularReminderses.size() > 0) {
            if (executorService == null) {
                executorService = Executors.newScheduledThreadPool(regularReminderses.size());
            }
            executorService.scheduleAtFixedRate(new SysRemindTimerTask(), 0L, 1L, TimeUnit.MINUTES);
//            for (RegularReminders reminders : regularReminderses) {
//                if (Sysconstant.remindType_1.equals(reminders.getRemindType())) {
//
//                } else if (Sysconstant.remindType_2.equals(reminders.getRemindType())) {
//
//                }
//            }


        }
    }


    @Override
    protected void finalize() throws Throwable {
        if (executorService != null) {
            executorService.shutdown();
        }
        super.finalize();
    }


}
